home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume3 / nobs < prev    next >
Encoding:
Text File  |  1989-02-03  |  4.9 KB  |  161 lines

  1. Path: xanth!mcnc!rutgers!cmcl2!husc6!necntc!ncoast!allbery
  2. From: chad@anasaz.UUCP
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i044: backspace filter
  5. Keywords: backspace printer filter nroff
  6. Message-ID: <8806080635.AA08248@csd1.milw.wisc.edu>
  7. Date: 8 Jun 88 06:35:22 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Reply-To: chad@anasaz.UUCP ()
  10. Organization: DCF Inc, Phoenix AZ
  11. Lines: 147
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. comp.sources.misc: Volume 3, Issue 44
  15. Submitted-By: "A. Nonymous" <chad@anasaz.UUCP>
  16. Archive-Name: nobs
  17.  
  18. [Why not "col -b"?  ++bsa]
  19.  
  20. This is a filter that has probably been written a thousand times, but
  21. here is another version.  It is used to clean up nroff output
  22. generated for the default TTY37 terminal for printing on a printer
  23. that cannot backspace (or one that beats itself silly when it does):
  24.     nroff -man foo.1 | nobs > foo.man
  25. It has been tested on SysVr2, but should work anywhere.
  26. ----(cut)--------(cut)--------(cut)--------(cut)--------(cut)----
  27. #! /bin/sh
  28. # This is a shell archive.  Remove anything before this line, then unpack
  29. # it by saving it into a file and typing "sh file".  To overwrite existing
  30. # files, type "sh file -c".  You can also feed this as standard input via
  31. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  32. # will see the following message at the end:
  33. #        "End of shell archive."
  34. # Contents:  Makefile nobs.c
  35. # Wrapped by chad@anasaz on Tue Jun  7 20:13:35 1988
  36. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  37. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  38.   echo shar: Will not clobber existing file \"'Makefile'\"
  39. else
  40. echo shar: Extracting \"'Makefile'\" \(238 characters\)
  41. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  42. X# %M% for nobs
  43. X
  44. XBINDIR = /usr/local/bin
  45. XTARGET = nobs
  46. X
  47. X$(TARGET): nobs.c
  48. X    $(CC) $(CFLAGS) -o $(TARGET) nobs.c
  49. X
  50. Xinstall: nobs
  51. X    strip nobs
  52. X    @-rm $(BINDIR)/$(TARGET)
  53. X    ln $(TARGET) $(BINDIR)
  54. X    touch install
  55. X
  56. XLint:    nobs.c
  57. X    lint -p nobs.c >Lint
  58. END_OF_FILE
  59. if test 238 -ne `wc -c <'Makefile'`; then
  60.     echo shar: \"'Makefile'\" unpacked with wrong size!
  61. fi
  62. # end of 'Makefile'
  63. fi
  64. if test -f 'nobs.c' -a "${1}" != "-c" ; then 
  65.   echo shar: Will not clobber existing file \"'nobs.c'\"
  66. else
  67. echo shar: Extracting \"'nobs.c'\" \(2474 characters\)
  68. sed "s/^X//" >'nobs.c' <<'END_OF_FILE'
  69. X/* nobs.c - Simple backspace filter - 1.1 */
  70. X
  71. X/*
  72. X** This program will take lines containing overstrike pragmas of
  73. X** the form <char><bs><char> and convert them to individual lines of
  74. X** output with a return but no line feed between them.
  75. X** Useful in filtering nroff output to line printers that cannot
  76. X** back space (or on which back spaces are expensive).
  77. X*/
  78. X
  79. X/*
  80. X** Author:
  81. X**   Chad R. Larson            This program is placed in the
  82. X**   DCF, Inc.                Public Domain.  You may do with
  83. X**   14623 North 49th Place        it as you please.
  84. X**   Scottsdale, AZ 85254
  85. X*/
  86. X
  87. X#include <stdio.h>
  88. X
  89. X#define    LINESIZE    512        /* maximum line length */
  90. X#define MAXOVER        8        /* maximum number of overstrikes */
  91. X
  92. X/* forward references */
  93. Xvoid exit();
  94. Xchar *memset();
  95. X
  96. Xstatic char input[LINESIZE];        /* input line buffer */
  97. Xstatic char output[MAXOVER][LINESIZE];    /* output line buffers */
  98. X
  99. Xvoid main()
  100. X{
  101. X    int        line;        /* output buffer array index */
  102. X    int        in_dex;        /* offset into input buffer */
  103. X    int        out_dex;    /* offset into output buffer */
  104. X    int        line_count;    /* number of output lines */
  105. X    int        strip;        /* trailing space strip index */
  106. X    char    chr;        /* single character storage */
  107. X
  108. X    /* loop through the input lines */
  109. X    while ( fgets(input, LINESIZE, stdin) != (char *)NULL ) {
  110. X
  111. X    /* init output buffers to blanks */
  112. X    memset( output, ' ', sizeof(output) );
  113. X
  114. X    /* slide through input line, dropping bs chars */
  115. X    out_dex = -1;        /* reset array pointers */
  116. X    in_dex = 0;
  117. X    line = 0;
  118. X    line_count = 0;
  119. X
  120. X    while ( ( chr = input[in_dex++] ) && chr != '\n' ) {
  121. X        if (chr != '\b') {
  122. X        line = 0;            /* back to main line */
  123. X        output[line][++out_dex] = chr;    /* stuff the character */
  124. X        } else {    /* got backspace */
  125. X        ++line;            /* select output buffer */
  126. X        if (line == MAXOVER) {
  127. X            fprintf(stderr, "Too many overstrikes!\n");
  128. X            exit(1);
  129. X        }
  130. X        output[line][out_dex] = input[in_dex++];
  131. X        line_count = (line_count < line) ? line : line_count;
  132. X        }
  133. X    } /* end of input line */
  134. X
  135. X    /* print the output buffers */
  136. X    for (line = 0; line <= line_count; line++) {
  137. X        strip = out_dex;
  138. X        while (output[line][strip] == ' ')    /* strip trailing spaces */
  139. X        --strip;
  140. X        ++strip;                /* point past string end */
  141. X        if (line < line_count)        /* new line or return? */
  142. X        output[line][strip] = '\r';
  143. X        else
  144. X        output[line][strip] = '\n';
  145. X        output[line][++strip] = '\0';    /* terminate string */
  146. X        fputs (output[line], stdout);    /* print it */
  147. X    }
  148. X
  149. X    } /* end of file */
  150. X    exit(0);
  151. X
  152. X} /* end of main */
  153. END_OF_FILE
  154. if test 2474 -ne `wc -c <'nobs.c'`; then
  155.     echo shar: \"'nobs.c'\" unpacked with wrong size!
  156. fi
  157. # end of 'nobs.c'
  158. fi
  159. echo shar: End of shell archive.
  160. exit 0
  161.